import { BrowserWindow, app,Menu } from 'electron';
import { MainWindowPath } from '../projectPath';
import { App } from '../mainWindow';
import path from 'node:path';
import fs from 'fs'
let childWindow: Electron.BrowserWindow | null;

export const newwinApp = {
    initNewWindow(data) {
		Menu.setApplicationMenu(null) // 去掉菜单栏
        childWindow = new BrowserWindow({
            width: data.width,
            height: data.height,
			show: false,
			parent:App.getMainWindow(),
			frame: false,
			modal:true,
            webPreferences: {
                nodeIntegration: true,
                contextIsolation: true,
                backgroundThrottling: false,
                preload: path.join(__dirname, 'preload.js')
            },
        });
		
		childWindow?.loadURL(MainWindowPath+`#/${data.url}`);

        childWindow.once("ready-to-show", () => {
          if (process.argv.indexOf("--openAsHidden") < 0) 
              childWindow.show();
        });

        childWindow.on("close", (event) => {
		
        })
    },
    showDevTools() {
        childWindow?.webContents.openDevTools();
    },
    getNewWindow() {
        return childWindow;
    }
}